Skip to content

Method: withPmOf(String, Collection)

1: /*
2: * *************************************************************************************************************************************************************
3: *
4: * TheseFoolishThings: Miscellaneous utilities
5: * http://tidalwave.it/projects/thesefoolishthings
6: *
7: * Copyright (C) 2009 - 2024 by Tidalwave s.a.s. (http://tidalwave.it)
8: *
9: * *************************************************************************************************************************************************************
10: *
11: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
12: * You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
17: * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
18: *
19: * *************************************************************************************************************************************************************
20: *
21: * git clone https://bitbucket.org/tidalwave/thesefoolishthings-src
22: * git clone https://github.com/tidalwave-it/thesefoolishthings-src
23: *
24: * *************************************************************************************************************************************************************
25: */
26: package it.tidalwave.role.ui;
27:
28: import javax.annotation.Nonnull;
29: import java.util.Collection;
30: import java.util.Optional;
31: import java.util.Set;
32: import it.tidalwave.role.Aggregate;
33: import lombok.AccessLevel;
34: import lombok.RequiredArgsConstructor;
35: import lombok.ToString;
36:
37: /***************************************************************************************************************************************************************
38: *
39: * A specialisation of {@link Aggregate}{@code <PresentationModel>} which offers a convenience method for aggregating
40: * its contained objects.
41: *
42: * @author Fabrizio Giudici
43: * @since 3.2-ALPHA-3
44: *
45: **************************************************************************************************************************************************************/
46: @RequiredArgsConstructor(access = AccessLevel.PRIVATE) @ToString
47: public class PresentationModelAggregate implements Aggregate<PresentationModel>
48: {
49: @Nonnull
50: private final Aggregate<PresentationModel> delegate;
51:
52: /***********************************************************************************************************************************************************
53: * Creates a new, empty instance.
54: *
55: * @return the new instance
56: **********************************************************************************************************************************************************/
57: @Nonnull
58: public static PresentationModelAggregate newInstance()
59: {
60: return new PresentationModelAggregate(Aggregate.newInstance());
61: }
62:
63: /***********************************************************************************************************************************************************
64: * Adds another {@link PresentationModel} with the given roles, associated to the given name. With a plain
65: * {@link Aggregate}{@code <PresentationModel>} the code would be:
66: *
67: * <pre>
68: * Aggregate<PresentationModel> aggregate = Aggregate.newInstance()
69: * .with("name", PresentationModel.of("", r(role1, role2, role3));
70: * </pre>
71: *
72: * The simplified code is:
73: *
74: * <pre>
75: * Aggregate<PresentationModel> aggregate = PresentationModelAggregate.newInstance()
76: * .withPmOf("name", r(role1, role2, role3));
77: * </pre>
78: *
79: * @param name the name of the {@code PresentationModel}
80: * @param roles the roles
81: * @return the new {@code PresentationModel}
82: **********************************************************************************************************************************************************/
83: @Nonnull
84: public PresentationModelAggregate withPmOf (@Nonnull final String name, @Nonnull final Collection<Object> roles)
85: {
86: return new PresentationModelAggregate(delegate.with(name, PresentationModel.of("", roles)));
87: }
88:
89: /***********************************************************************************************************************************************************
90: * {@inheritDoc}
91: **********************************************************************************************************************************************************/
92: @Override @Nonnull
93: public Optional<PresentationModel> getByName (@Nonnull final String name)
94: {
95: return delegate.getByName(name);
96: }
97:
98: /***********************************************************************************************************************************************************
99: * {@inheritDoc}
100: **********************************************************************************************************************************************************/
101: @Override @Nonnull
102: public Set<String> getNames()
103: {
104: return delegate.getNames();
105: }
106: }